package com.ax.api.route.base.blog;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import com.ax.api.route.util.RouteConfig;
@RestController
@RequestMapping("/blog")
public class BlogRoute {
	    @Autowired
	    LoadBalancerClient loadBalancerClient;
	    @Autowired
	    RestTemplate restTemplate;
	    
	    
	@GetMapping("/blogconsumer")
	public String consumer() {
	    ServiceInstance serviceInstance = loadBalancerClient.choose(RouteConfig.BASE_ROUTE);
	    String url = "http://" + serviceInstance.getHost() + ":" + serviceInstance.getPort() + "/getSessionId";
	    return restTemplate.getForObject(url, String.class);
  }
	    
}
